//
//  SelectedImagUpDataImagView.m
//  NtoccDriverNew
//
//  Created by 张天兴 on 2025/9/15.
//  Copyright © 2025 GCY. All rights reserved.
//

#import "SelectedImagUpDataImagView.h"



@implementation SelectedImagUpDataImagView

- (instancetype)initWithFrame:(CGRect)frame ImgStr:(NSString *)imgStr{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:22/255.0 green:46/255.0 blue:60/255.0 alpha:0.8];
        self.imgURLStr = imgStr;
        [self setUI];
    }
    return self;
}
- (void)setUI{
    [self addSubview: self.topImagView];
    [self addSubview:self.bottomView];
}

- (UIImageView *)topImagView{
    if (_topImagView == nil) {
        self.topImagView = [[UIImageView alloc] initWithFrame:CGRectMake(15, StatusBarHeight, ScreenW - 30, ScreenH - 210 - StatusBarHeight)];
        [self.topImagView setImage:[UIImage imageNamed:self.imgURLStr]];
    }
    return _topImagView;
}

- (UIView *)bottomView{
    if (_bottomView == nil) {
        self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenH - 210, ScreenW, 210)];
        self.bottomView.backgroundColor = [UIColor whiteColor];
        [self.bottomView addSubview:self.takeAPhotoButton];
        [self.bottomView addSubview:self.photoPictureButton];
        [self.bottomView addSubview:self.centenButton];
    }
    return _bottomView;
}

- (UIButton *)takeAPhotoButton{
    if (_takeAPhotoButton == nil) {
        self.takeAPhotoButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.takeAPhotoButton.frame = CGRectMake(0, 0, ScreenW, 56);
        [self.takeAPhotoButton setTitle:@"拍照" forState:(UIControlStateNormal)];
        [self.takeAPhotoButton setTitleColor:[UIColor colorWithRed:0 green:167/255.0 blue:157/255.0 alpha:1] forState:(UIControlStateNormal)];
        [self.takeAPhotoButton addTarget:self action:@selector(takeAPhotoButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        UILabel *linesLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.takeAPhotoButton.frame), ScreenW, 1)];
        linesLabel.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
        [self.bottomView addSubview:linesLabel];
    }
    return _takeAPhotoButton;
}
- (UIButton *)photoPictureButton{
    if (_photoPictureButton == nil) {
        self.photoPictureButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.photoPictureButton.frame = CGRectMake(0, CGRectGetMaxY(self.takeAPhotoButton.frame) + 1, ScreenW, 56);
        [self.photoPictureButton setTitle:@"相册中选择" forState:(UIControlStateNormal)];
        [self.photoPictureButton setTitleColor:[UIColor colorWithRed:0 green:167/255.0 blue:157/255.0 alpha:1] forState:(UIControlStateNormal)];
        [self.photoPictureButton addTarget:self action:@selector(photoPictureButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        UILabel *linesLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.photoPictureButton.frame), ScreenW, 10)];
        linesLabel.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
        [self.bottomView addSubview:linesLabel];
    }
    return _photoPictureButton;
}
- (UIButton *)centenButton{
    if (_centenButton == nil) {
        self.centenButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.centenButton.frame = CGRectMake(0, CGRectGetMaxY(self.photoPictureButton.frame) + 10, ScreenW, 56);
        [self.centenButton setTitle:@"取消" forState:(UIControlStateNormal)];
        [self.centenButton addTarget:self action:@selector(centenButtonAction) forControlEvents:(UIControlEventTouchUpInside)];

        [self.centenButton setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1] forState:(UIControlStateNormal)];
    }
    return _centenButton;
}
- (void)takeAPhotoButtonAction{//拍照
    if (self.selectedType) {
        self.selectedType(@"1");
    }
}
- (void)photoPictureButtonAction{//相册
    if (self.selectedType) {
        self.selectedType(@"2");
    }
}
- (void)centenButtonAction{//取消
    if (self.selectedType) {
        self.selectedType(@"3");
    }
}
@end
